home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10911 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  81 lines

  1. Path: inforamp.net!ts31-02
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How can I include IOSTREAM.H only once?
  5. Date: Mon, 11 Mar 96 06:05:40 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4i0fs4$5g9@sam.inforamp.net>
  8. References: <4hbi55$899@sam.inforamp.net> <4hc09v$136@news1.usa.pipeline.com> <4hj42l$elu@sam.inforamp.net> <4hqck8$fvc@uuneo.neosoft.com> <4hsgid$pmm@sam.inforamp.net> <4htg6a$593@news4.digex.net>
  9. NNTP-Posting-Host: ts31-02.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4htg6a$593@news4.digex.net>, ell@access1.digex.net (Ell) wrote:
  13. >Randy Charles Morin (rmorin@inforamp.net) wrote:
  14. >: >#ifndef __STDIO__
  15. >: >#include <stdio.h>
  16. >: >#endif
  17. >
  18. >And generally the '#endif' is the last of code in the file.
  19. >#ifndef __STDIO__
  20. >#include <stdio.h>
  21. > /*...code...*/
  22. > /*...code...*/
  23. >#endif
  24.  
  25. Sorry, but this is wrong.  Everybody, including myself is almost always 
  26. wrong, so let's not belabor the point.  What I was attempting to do is include 
  27. a file only if it has not already been included.  Surely the file <stdio.h> 
  28. has simliar pre-compile statements to what you describe, but the include file 
  29. will still be loaded during pre-compilation without using the pre-compile 
  30. statements I describe.  My statement load the file only if they have not 
  31. been pre-loaded, as oppose to the other statements compiling the file only if 
  32. they have not been previously compiled.  
  33.  
  34. Example:
  35.  
  36. header.h
  37. --------
  38. #ifndef HEADER_H
  39. #define HEADER_H
  40. typedef bool int;
  41. #endif
  42. ------
  43.  
  44. source.cpp
  45. ----------
  46. #ifndef HEADER_H
  47. #include "header.h"
  48. #endif
  49. #ifndef HEADER_H
  50. #include "header.h"
  51. #endif
  52. int main()
  53. {
  54.     bool b;
  55.     int i=0;
  56.     b=i;
  57.     return b;
  58. };
  59. -----
  60.  
  61. source2.cpp
  62. ----------
  63. #include "header.h"
  64. #include "header.h"
  65. int main()
  66. {
  67.     bool b;
  68.     int i=0;
  69.     b=i;
  70.     return b;
  71. };
  72. -----
  73.  
  74. source.cpp will compile faster then source2.cpp because the first source loads 
  75. the header file once, while the second source loads the header file twice.  
  76. This is a simply example and no noticeable compile time savings will occur.  
  77. But if all standard headers used this type of syntax, then compile times would 
  78. greatly increase.
  79.  
  80. Agrivar
  81.